package com.foreknow.traning;

public class Order {
    private String orderId;//订单属性

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public double getOrderPrice() {
        return orderPrice;
    }

    public void setOrderPrice(double orderPrice) {
        this.orderPrice = orderPrice;
    }

    public OrderItem[] getItems() {
        return items;
    }

    public void setItems(OrderItem[] items) {
        this.items = items;
    }

    private double orderPrice;//订单总额
    private OrderItem[] items;//保存多个订单项
    private double total;

    public double getTotal() {
        //调用计算总额
        calTotal();
        return total;
    }

    public void setTotal(double total) {
        this.total = total;
    }

    public Order(String orderId) {
        this.orderId = orderId;
        this.items = new OrderItem[3];
    }

    public void  calTotal(){
        double total = 0;
        //对数组遍历
        if (items!= null){
            for (int i = 0;i < items.length;i++){
                total += items[i].getNum() * items[i].getPprice();
            }
        }
        this.total = total;
    }
}
